package aiowang.javaprimary.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Copyright (C), 2017-2021, aiowang
 * Date: 2021/8/25 16:28
 * FileName: ConnectionUtil
 * Description:
 * @author aiowang
 */
public class RabbitMqUtils {

    public static Connection getConnection() throws IOException, TimeoutException {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.0.234");
        factory.setPort(5672);
        //设置Virtual Host
        //factory.setVirtualHost("/");
        factory.setUsername("admin");
        factory.setPassword("123");
        //通过工厂获取连接
        Connection connection = factory.newConnection();
        return connection;
    }

    public static Channel getChannel() throws IOException, TimeoutException {
        return getConnection().createChannel();
    }

}
